package com.hr.quartz.task;

import com.hr.common.core.domain.vo.SysUserVO;
import com.hr.common.utils.DateUtils;
import com.hr.system.domain.SysPersonnelClock;
import com.hr.system.domain.SysTenant;
import com.hr.system.service.ISalaryService;
import com.hr.system.service.ISysTenantService;
import com.hr.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.hr.common.utils.StringUtils;
import com.hr.system.service.ISysPersonnelClockService;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {

    @Autowired
    private ISysPersonnelClockService sysPersonnelClockService;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISalaryService signedService;

    @Autowired
    private ISysTenantService sysTenantService;


    public void monthEndSalaryHandle()
    {
        System.out.println(" =================开始执行月末工资处理调度任务============ ");
        signedService.salarySettlement();
        System.out.println(" =================月末工资处理调度任务执行完成============ ");
    }

    public void monthEndTenantHandle()
    {
        System.out.println(" =================开始执行租户状态调度任务============ ");
        Date nowDate = DateUtils.getNowDate();
        List<SysTenant> sysTenants = sysTenantService.selectSysTenantList(new SysTenant());
        for (SysTenant sysTenant : sysTenants) {
            if (nowDate.after(sysTenant.getTenantEndTime())) {
                sysTenant.setTenantStatus("1");
                sysTenantService.updateSysTenant(sysTenant);
            }
        }
        System.out.println(" =================月末租户状态调度任务执行完成============ ");
    }


    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
    }


    public void clockStatusUpdate()
    {
        System.out.println(" =================开始执行打卡状态任务调度============ ");
        //每天凌晨1点执行打卡状态更新
        sysPersonnelClockService.updateCurrentDateClocks();
        //执行新增一天空打卡数据
        List<SysPersonnelClock> clocks = new ArrayList<SysPersonnelClock>();
        List<SysUserVO> sysUserVOList = userService.selectUserVO();
        for (SysUserVO sysUserVO : sysUserVOList) {
            clocks.add(new SysPersonnelClock(DateUtils.getNextDate(1),DateUtils.getWeek(DateUtils.getNextDate(1)),sysUserVO.getUserId(),sysUserVO.getTenantId()));
        }
        //批量插入
        sysPersonnelClockService.batchInsertClock(clocks);
        System.out.println(" =================打卡状态任务调度完成============ ");
    }
}
